package com.akuma.swing;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URL;
//Download by http://www.codefans.net
//程序启动界面

public class Main extends JWindow implements Runnable {
    Thread splashThread;  //进度条更新线程
    PopupMenu popupMenu1 = new PopupMenu();

    public Main() {
        isTray();
        addWindowListener(new WindowAdapter() {
            public void windowIconified(WindowEvent evt) {
                unVisible();
            }
        });
    }

    public void unVisible() {
        this.setVisible(false);
    }

    public void isTray() {
        try {
            if (SystemTray.isSupported()) {// 判断当前平台是否支持系统托盘　
                SystemTray st = SystemTray.getSystemTray();
                Image image = Toolkit.getDefaultToolkit().getImage("login.png");//定义托盘图标的图片　　
                TrayIcon ti = new TrayIcon(image);
                ti.setToolTip("test ");
                ti.setPopupMenu(this.popupMenu1);
                st.add(ti);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void start() {
        this.toFront();  //窗口前端显示
        splashThread = new Thread(this);  //实例化线程
        splashThread.start();  //开始运行线程
    }

    public void run() {
        setVisible(true); //显示窗口
        showFrame(); //运行主程序
    }

    static void showFrame() {
        new MyWindow("程序启动界面演示"); //实例化JFrame对象
    }

    public static void main(String[] args) {
        Main splash = new Main();
        splash.start();  //运行启动界面
    }
}